﻿using System;
using System.IO;
using System.Runtime.InteropServices;

namespace SystemModule
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1, Size = 4515)]
    public class THumDataInfo // Size 4515
    {
        public TRecordHeader Header;
        public THumData Data;


        public THumDataInfo()
        {
            this.Header = new TRecordHeader();
            this.Data = new THumData();
        }

        public THumDataInfo(byte[] buff)
        {
            var hederBuff = new byte[28];
            Array.Copy(buff, 0, hederBuff, 0, hederBuff.Length);
            Header = new TRecordHeader(hederBuff);
            var dataBuff = new byte[4487];
            Array.Copy(buff, 29, dataBuff, 0, dataBuff.Length);
            Data = new THumData(dataBuff);
        }

        public byte[] ToByte()
        {
            using (var memoryStream = new MemoryStream())
            {
                var backingStream = new BinaryWriter(memoryStream);

                backingStream.Write(Header.ToByte());
                backingStream.Write(Data.ToByte());//4487 4377

                var stream = backingStream.BaseStream as MemoryStream;
                return stream.ToArray();
            }
        }

    }
}